/**
 * Author  zxy
 * Date  2023/6/21 下午 3:51
 */
public class CalculateDays {

    private static boolean isRun(int year) {
        int temp1 = year % 100;
        int temp2 = year % 1000;
        boolean flag = (temp1 == 0 || temp2 == 0);

        if (flag) {
            return year % 400 != 0;
        } else {
            return year % 4 != 0;
        }
    }


    private static int numberOfDays(String left, String right) {

        String year1 = left.substring(0, 4);
        String month1 = left.substring(5, 7);
        String day1 = left.substring(8, 10);

        String year2 = right.substring(0, 4);
        String month2 = right.substring(5, 7);
        String day2 = right.substring(8, 10);

        int year_1 = Integer.parseInt(year1);
        int month_1 = Integer.parseInt(month1);
        int day_1 = Integer.parseInt(day1);

        int year_2 = Integer.parseInt(year2);
        int month_2 = Integer.parseInt(month2);
        int day_2 = Integer.parseInt(day2);

        int cnt = 0;

        if (year_1 != year_2) {
            for (int i = 1; i < month_2; i++) {
                if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12) {
                    cnt += 31;
                } else if (i != 2) {
                    cnt += 30;
                } else {
                    if (isRun(year_2)) {
                        cnt += 28;
                    } else {
                        cnt += 29;
                    }
                }
            }

            cnt += day_2;

            for (int i = month_1; i <= 12; i++) {
                if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12) {
                    if (i == month_1) {
                        cnt += 31 - day_1;
                    } else {
                        cnt += 31;
                    }
                } else if (i != 2) {
                    if (i == month_1) {
                        cnt += 30 - day_1;
                    } else {
                        cnt += 30;
                    }
                } else {
                    // 闰年
                    int day = 28;
                    if (isRun(year_2)) {
                        day = 28;
                    } else {
                        day = 29;
                    }


                    if (i == month_1) {
                        cnt += day - day_1;
                    } else {
                        cnt += day;
                    }
                }
            }

            for (int i = year_1 + 1; i < year_2; i++) {
                if (isRun(i)) {
                    cnt += 365;
                } else {
                    // Stem.out.println(i);
                    cnt += 366;
                }
            }

        } else {
            for (int i = month_1; i < month_2; i++) {
                if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12) {
                    if (i == month_1) {
                        cnt += 31 - day_1;
                    } else {
                        cnt += 31;
                    }
                } else if (i != 2) {
                    if (i == month_1) {
                        cnt += 30 - day_1;
                    } else {
                        cnt += 30;
                    }
                } else {
                    // 闰年
                    int day = 28;
                    if (isRun(year_2)) {
                        day = 28;
                    } else {
                        day = 29;
                    }

                    if (i == month_1) {
                        cnt += day - day_1;
                    } else {
                        cnt += day;
                    }
                }
            }
            cnt += day_2;
        }

        return cnt;
    }

}

